//
//  CampustQuesionDetailHeaderView.m
//  ShowYork
//
//  Created by hxh on 2021/3/29.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "CampustQuesionDetailHeaderView.h"

@interface CampustQuesionDetailHeaderView ()
@property (nonatomic,strong)UILabel *contentLb;
@property (nonatomic,strong)UILabel *dateLb;
@property (nonatomic,strong)UILabel *nameLb;
@property (nonatomic,strong)UIImageView *headerIcon;
@property (nonatomic,strong)UIView *line;
@property (nonatomic,strong)UIView *containView;

@end

@implementation CampustQuesionDetailHeaderView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}
- (void)setUI{
        
    self.containView = [[UIView alloc]init];
    
    [self addSubview:self.containView];
    
    [self.containView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(self).priorityHigh();
        make.width.mas_equalTo(kScreenW);
    }];
    
    
    self.contentLb = [[UILabel alloc]init];
    self.contentLb.numberOfLines = 0;
    self.contentLb.font = [UIFont boldSystemFontOfSize:15];
    [self.containView addSubview:self.contentLb];
    
    [self.contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.containView).offset(16);
        make.left.equalTo(self.containView).offset(20);
        make.right.equalTo(self.containView).offset(-20);
    }];
    
    self.headerIcon = [[UIImageView alloc]init];
    self.headerIcon.layer.cornerRadius = 10;
    self.headerIcon.layer.masksToBounds = YES;
    [self.containView addSubview:self.headerIcon];
    [self.headerIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLb.mas_bottom).offset(20);
        make.left.equalTo(self.contentLb);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];

    self.nameLb = [[UILabel alloc]init];
    self.nameLb.textColor = C153;
    self.nameLb.font = font(12);
    [self.containView addSubview:self.nameLb];
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.headerIcon);
        make.left.equalTo(self.headerIcon.mas_right).offset(8);
    }];
    
    self.dateLb = [[UILabel alloc]init];
    self.dateLb.textColor = RGBA(173, 173, 173, 173);
    self.dateLb.font = font(10);
    [self.containView addSubview:self.dateLb];
    [self.dateLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.headerIcon);
        make.right.equalTo(self.contentLb);
    }];
    
    self.line = [[UIView alloc]init];
    self.line.backgroundColor = RGBA(230, 230, 230, 1);
    [self.containView addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentLb);
        make.height.mas_equalTo(0.5);
        make.top.equalTo(self.headerIcon.mas_bottom).offset(32);
    }];
    
    UITapGestureRecognizer *headTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showUserInfo)];
    self.headerIcon.userInteractionEnabled = YES;
    [self.headerIcon addGestureRecognizer:headTap];
    
    UITapGestureRecognizer *nameTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showUserInfo)];
    self.nameLb.userInteractionEnabled = YES;
    [self.nameLb addGestureRecognizer:nameTap];
}

- (void)showUserInfo{
    if (self.delegate && [self.delegate respondsToSelector:@selector(showCreateUserInfo)]) {
        [self.delegate showCreateUserInfo];
    }
}

- (void)setModel:(CampusQuestionDetailModel *)model{
    _model = model;
    self.contentLb.text = model.question;
    self.dateLb.text = model.createDetailTimeStr;
    self.nameLb.text = model.userVM.realName;
    
    
    if (model.userVM.imagePath.length == 0) {
        if (model.userVM.sex.intValue == 0) {
            self.headerIcon.image = [UIImage imageNamed:@"defaut_header"];
        }else if (model.userVM.sex.intValue == 1){
            self.headerIcon.image = [UIImage imageNamed:@"common_boy_tag"];
        }else{
            self.headerIcon.image = [UIImage imageNamed:@"common_girl_tag"];
        }
    }else{
        [self.headerIcon sd_setImageWithURL:[NSURL URLWithString:model.userVM.imagePath]];
    }
}


@end
